package cn.edu.scau.cmi.ema.domain;


import com.alibaba.fastjson.annotation.JSONField;

import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.io.Serializable;

@Entity
@NamedQueries({ @NamedQuery(name = "findAllRulecolumns", query = "select myRulecolumn from Rulecolumn myRulecolumn"),
		@NamedQuery(name = "findRulecolumnByName", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.name = ?1"),
		@NamedQuery(name = "findRulecolumnByNameContaining", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findRulecolumnByExcelcolumn", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.excelcolumn = ?1"),
		@NamedQuery(name = "findRulecolumnByExcelcolumnalphabet", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.excelcolumnalphabet = ?1"),
		@NamedQuery(name = "findRulecolumnByExcelcolumnalphabetContaining", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.excelcolumnalphabet like concat('%',?1,'%')"),
		@NamedQuery(name = "findRulecolumnByPartion", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.partion = ?1"),
		@NamedQuery(name = "findRulecolumnByDescription", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.description = ?1"),
		@NamedQuery(name = "findRulecolumnByDescriptionContaining", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllRulecolumnsByRulefield", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.rulefield.id = ?1"),
		@NamedQuery(name = "findRulecolumnById", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.id = ?1"),
		@NamedQuery(name = "findRulecolumnByPrimaryKey", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.id = ?1 "),
		@NamedQuery(name = "deleteRulecolumnsByIds", query = "delete Rulecolumn where id in (?1)"),
		@NamedQuery(name = "findRulecolumnsByIds", query = "select myRulecolumn from Rulecolumn myRulecolumn where myRulecolumn.id in (?1)"),
		@NamedQuery(name = "findRulecolumnByPhyscialPrimaryKey", query = "select myRulecolumn from Rulecolumn myRulecolumn where  myRulecolumn.rulefield.id = ?1 and myRulecolumn.excelcolumn = ?2 and myRulecolumn.partion = ?3"),
		@NamedQuery(name = "countRulecolumnsByName", query = "select count(myRulecolumn)  from Rulecolumn myRulecolumn where myRulecolumn.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "rulecolumn")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Rulecolumn")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Rulecolumn implements Serializable, Comparable<Rulecolumn> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "excelcolumn")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer excelcolumn;

	@Column(name = "excelcolumnalphabet")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String excelcolumnalphabet;

	@Column(name = "partion")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer partion;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "rulefield", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Rulefield rulefield;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setExcelcolumn(Integer excelcolumn) {
		this.excelcolumn = excelcolumn;
	}

	public Integer getExcelcolumn() {
		return this.excelcolumn;
	}

	public void setExcelcolumnalphabet(String excelcolumnalphabet) {
		this.excelcolumnalphabet = excelcolumnalphabet;
	}

	public String getExcelcolumnalphabet() {
		return this.excelcolumnalphabet;
	}

	public void setPartion(Integer partion) {
		this.partion = partion;
	}

	public Integer getPartion() {
		return this.partion;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setRulefield(Rulefield rulefield) {
		this.rulefield = rulefield;
	}

	public Rulefield getRulefield() {
		return rulefield;
	}

	public void copy(Rulecolumn that) {

		setId(that.getId());

		setName(that.getName());
		setExcelcolumn(that.getExcelcolumn());
		setExcelcolumnalphabet(that.getExcelcolumnalphabet());
		setPartion(that.getPartion());
		setDescription(that.getDescription());

		setRulefield(that.getRulefield());

	}

	public Rulecolumn() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("excelcolumn=[").append(excelcolumn).append("] ");
		buffer.append("excelcolumnalphabet=[").append(excelcolumnalphabet).append("] ");
		buffer.append("partion=[").append(partion).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Rulecolumn))
			return false;
		Rulecolumn comparedRulecolumn = (Rulecolumn) obj;
		if (!CheckPropertyEqual(this.rulefield.id, comparedRulecolumn.rulefield.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.excelcolumn, comparedRulecolumn.excelcolumn)) {
			return false;
		}
		if (!CheckPropertyEqual(this.partion, comparedRulecolumn.partion)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Rulecolumn o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
